package com.example.calculation.service.impl;

import com.example.calculation.entity.Calculation;
import com.example.calculation.service.DroolsService;
import org.kie.api.KieBase;
import org.kie.api.runtime.KieSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: whb
 * @Date: 2021/10/11 16:49
 * @Description
 */
@Service
public class DroolsServiceImpl implements DroolsService {

    @Autowired
    private KieBase kieBase;

    @Override
    public Calculation calculate(double wage) {
        KieSession session = kieBase.newKieSession();
        Calculation calculation = new Calculation();
        calculation.setWage(wage);
        session.insert(calculation);
        session.fireAllRules();
        session.dispose();
        return calculation;
    }
}
